package leetcode.median;

import java.util.HashMap;
import java.util.Map;

public class $454_FourSumCount {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer, Integer> map1 = new HashMap<>();
        int res = 0;

        for (int i = 0;i < nums1.length;i++) {
            for (int j = 0;j < nums2.length;j++) {
                int sum = nums1[i] + nums2[j];
                int originValue = map1.getOrDefault(sum, 0);
                map1.put(sum, originValue + 1);
            }
        }

        for (int i = 0;i < nums3.length;i++) {
            for (int j = 0;j < nums4.length;j++) {
                res += map1.getOrDefault(-nums3[i] - nums4[j], 0);
            }
        }
        return res;
    }
}
